package school.community.controller;

import school.community.dto.InfoDTO;
import school.community.enums.NotificationTypeEnum;
import school.community.model.Info;
import school.community.service.InfoService;
import school.community.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class CheckController {

  @Autowired
  private InfoService infoService;

  @Autowired
  private NotificationService notificationService;

  @GetMapping("/check/{id}")
  public String check(@PathVariable(name = "id") Long id) {
    Info info = new Info();
    info.setId(id);
    info.setState(1);
    infoService.updataState(info);
    InfoDTO infoDTO = infoService.getById(id);
    notificationService.createNotify(3L,infoDTO.getCreator(),"admin",infoDTO.getId(),infoDTO.getTitle(), NotificationTypeEnum.PASS_ACTIVITY);
    return "redirect:/profile/waitCheck";
  }
}
